package com.rzz.overalldemo.controller;


import com.rzz.overalldemo.common.RespBean;
import com.rzz.overalldemo.pojo.User;
import com.rzz.overalldemo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author rzz
 * @since 2021-07-29
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @GetMapping("list")
    public RespBean list(@RequestParam Long id) {
        return RespBean.success("ok", userService.view(id));
    }

    @PostMapping("add")
    public RespBean add(@RequestBody User user) {
        Boolean count = userService.add(user);
        return RespBean.success("ok", count);
    }

    @PostMapping("update")
    public RespBean update(@RequestBody User user) {
        Boolean count = userService.updateUse(user);
        return RespBean.success("ok", count);
    }

    @DeleteMapping("delete")
    public RespBean delete(@RequestParam Long id) {
        Boolean count = userService.delete(id);
        return RespBean.success("ok", count);
    }

}
